<?php namespace My\Model;

//
class Cron extends \Phpcmf\Model\Cron {

    // 运行脚本
    public function run_cron() {

        // 自动关闭订单
        if ($this->mall_info['order']['pay_endtime']) {
            $rows = $this->table_site('order')->where('status=1 and pay_status=0')->getAll(10);
            if ($rows) {
                foreach ($rows as $data) {
                    \Phpcmf\Service::M('ocron', 'order')->pay($data, $this->mall_info['order']['pay_endtime']);
                }
            }
        }

        // 自动退款订单
        if ($this->mall_info['order']['deliver_endtime']) {
            $rows = $this->table_site('order')->where('status=1 and deliver_status=0')->getAll(10);
            if ($rows) {
                foreach ($rows as $data) {
                    \Phpcmf\Service::M('ocron', 'order')->deliver($data, $this->mall_info['order']['deliver_endtime']);
                }
            }
        }

        // 自动收货订单
        if ($this->mall_info['order']['receipt_endtime']) {
            $rows = $this->table_site('order')->where('status=2 and deliver_status=1')->getAll(10);
            if ($rows) {
                foreach ($rows as $data) {
                    \Phpcmf\Service::M('ocron', 'order')->receipt($data, $this->mall_info['order']['receipt_endtime']);
                }
            }
        }

        return parent::run_cron();
    }


}